/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.teach.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.istep.common.config.Global;
import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.web.BaseController;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.modules.teach.entity.TeachCtfsetcount;
import com.lczyfz.istep.modules.teach.service.TeachCtfsetcountService;

/**
 * CTF题目集计数表Controller
 * @author cqh
 * @version 2017-05-25
 */
@Controller
@RequestMapping(value = "${adminPath}/teach/teachCtfsetcount")
public class TeachCtfsetcountController extends BaseController {

	@Autowired
	private TeachCtfsetcountService teachCtfsetcountService;
	
	@ModelAttribute
	public TeachCtfsetcount get(@RequestParam(required=false) String id) {
		TeachCtfsetcount entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = teachCtfsetcountService.get(id);
		}
		if (entity == null){
			entity = new TeachCtfsetcount();
		}
		return entity;
	}
	
	@RequiresPermissions("teach:teachCtfsetcount:view")
	@RequestMapping(value = {"list", ""})
	public String list(TeachCtfsetcount teachCtfsetcount, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TeachCtfsetcount> page = teachCtfsetcountService.findPage(new Page<TeachCtfsetcount>(request, response), teachCtfsetcount); 
		model.addAttribute("page", page);
		return "modules/teach/teachCtfsetcountList";
	}

	@RequiresPermissions("teach:teachCtfsetcount:view")
	@RequestMapping(value = "form")
	public String form(TeachCtfsetcount teachCtfsetcount, Model model) {
		model.addAttribute("teachCtfsetcount", teachCtfsetcount);
		return "modules/teach/teachCtfsetcountForm";
	}

	@RequiresPermissions("teach:teachCtfsetcount:edit")
	@RequestMapping(value = "save")
	public String save(TeachCtfsetcount teachCtfsetcount, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, teachCtfsetcount)){
			return form(teachCtfsetcount, model);
		}
		teachCtfsetcountService.save(teachCtfsetcount);
		addMessage(redirectAttributes, "保存CTF题目集计数表成功");
		return "redirect:"+Global.getAdminPath()+"/teach/teachCtfsetcount/?repage";
	}
	
	@RequiresPermissions("teach:teachCtfsetcount:edit")
	@RequestMapping(value = "delete")
	public String delete(TeachCtfsetcount teachCtfsetcount, RedirectAttributes redirectAttributes) {
		teachCtfsetcountService.delete(teachCtfsetcount);
		addMessage(redirectAttributes, "删除CTF题目集计数表成功");
		return "redirect:"+Global.getAdminPath()+"/teach/teachCtfsetcount/?repage";
	}

}